package com.ruoyi.classroom.question.controller;


import com.ruoyi.classroom.question.domain.Question;
import com.ruoyi.classroom.question.service.IQuestionService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 答题管理Controller
 * 
 * @author lgm
 * @date 2024-07-26
 */
@RestController
@RequestMapping("/question/question")
public class QuestionController extends BaseController
{
    @Autowired
    private IQuestionService questionService;

    /**
     * 查询答题管理列表
     */
//    @RequiresPermissions("@ss.hasPermi('question:question:list')")
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:list")
    @GetMapping("/list")
    public TableDataInfo list(Question question)
    {
        startPage();
        List<Question> list = questionService.selectQuestionList(question);
        return getDataTable(list);
    }
    /**
     * 查询答题管理列表
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:list")
    @GetMapping("/listAnser")
    public TableDataInfo listAnser(Question question)
    {
        startPage();
        List<Question> list = questionService.selectQuestionListAnser(question);
        return getDataTable(list);
    }

    /**
     * 导出答题管理列表
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:export")
    @Log(title = "答题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Question question)
    {
        List<Question> list = questionService.selectQuestionList(question);
        ExcelUtil<Question> util = new ExcelUtil<Question>(Question.class);
        util.exportExcel(response, list, "答题管理数据");
    }

    /**
     * 获取答题管理详细信息
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(questionService.selectQuestionById(id));
    }

    /**
     * 新增答题管理
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:add")
    @Log(title = "答题管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Question question)
    {
        return toAjax(questionService.insertQuestion(question));
    }

    /**
     * 修改答题管理
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:edit")
    @Log(title = "答题管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Question question)
    {
        return toAjax(questionService.updateQuestion(question));
    }

    /**
     * 删除答题管理
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:remove")
    @Log(title = "答题管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(questionService.deleteQuestionByIds(ids));
    }
}
